package ai.people.core.security.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

import java.util.UUID;

/**
 * 组件配置
 *
 * @author yuanqinglong
 * @date 2022/4/17 13:31
 */
@Configuration
public class ComponentConfiguration {

    /**
     * token 令牌存储
     *
     * @param redisConnectionFactory 连接工厂
     * @return {@link RedisTokenStore}
     */
    @Bean
    public RedisTokenStore tokenStore(RedisConnectionFactory redisConnectionFactory){
        RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory);
        redisTokenStore.setAuthenticationKeyGenerator(authentication -> UUID.randomUUID().toString());
        return redisTokenStore;
    }
}
